namespace IMPlant.Core.Data.Ado.BaseSupport
{
    using IMPlant.Core.Data.Ado.Action;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Linq;
    using System.Runtime.InteropServices;

    public class AdoTemplete : DataOperationSurport
    {
        public AdoTemplete(string dbName) : base(dbName)
        {
        }

        public DataSet ExcuteFillDataSet(CommandType type, string text, DbParameter[] parameters = null, DbTransaction dbt = null)
        {
            IMPlant.Core.Data.Ado.Action.ExcuteFillDataSet action = new IMPlant.Core.Data.Ado.Action.ExcuteFillDataSet(type, text, parameters);
            return (base.Excute(action, dbt) as DataSet);
        }

        public List<T> ExcuteGetList<T>(CommandType type, string text, DbParameter[] parameters = null, DbTransaction dbt = null)
        {
            ExcuteList<T> action = new ExcuteList<T>(type, text, parameters);
            return ((IList)base.Excute(action, dbt)).Cast<T>().ToList<T>();
        }

        public T ExcuteGetObject<T>(CommandType type, string text, DbParameter[] parameters = null, DbTransaction dbt = null)
        {
            List<T> list = this.ExcuteGetList<T>(type, text, parameters, dbt);
            if ((list != null) && (list.Count > 0))
            {
                return list[0];
            }
            return default(T);
        }

        public int ExcuteNoQuery(CommandType type, string text, DbParameter[] parameters = null, DbTransaction dbt = null)
        {
            IMPlant.Core.Data.Ado.Action.ExcuteNoQuery action = new IMPlant.Core.Data.Ado.Action.ExcuteNoQuery(type, text, parameters);
            return (int)base.Excute(action, dbt);
        }

        public DataTable ExecuteFillDataTable(CommandType type, string text, DbParameter[] parameters = null, DbTransaction dbt = null)
        {
            ExcuteFillDataTable action = new ExcuteFillDataTable(type, text, parameters);
            return (base.Excute(action, dbt) as DataTable);
        }

        public object ExecuteScalar(CommandType type, string text, DbParameter[] parameters = null, DbTransaction dbt = null)
        {
            IMPlant.Core.Data.Ado.Action.ExecuteScalar action = new IMPlant.Core.Data.Ado.Action.ExecuteScalar(type, text, parameters);
            return base.Excute(action, dbt);
        }
    }
}

